#include<iostream.h>
#include<stdio.h>
#include<conio.h>
int searchValue(int inputArr[], int searchElem , int start, int end)
{
    int midValue;
    midValue = (start + end)/2;
    if(end<start)
    {
       return -1;
    }
    else if(inputArr[midValue] == searchElem)
    {
        return midValue;
        
    }
    else if(inputArr[midValue] < searchElem)
    {
         start = midValue + 1;
          return  searchValue(inputArr,searchElem,start,end);
    }
    else
    {
        end = midValue - 1;
        return searchValue(inputArr,searchElem,start,end);
    }

}
void testSearchValue()
{
     int inputArr[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},i,j,inputArrLen = 20,sum = 46,start , end = 19;
     for(i=0;i<inputArrLen;i++)
     {
          for(j= i+1;j<inputArrLen;j++)
          { 
                 int searchVal = sum - (inputArr[i] + inputArr[j]), start = j+1;
                 int temp = searchValue(inputArr,searchVal,start,end);
                 if(temp > -1)
                     cout<<"\n "<<inputArr[i]<<"  "<<inputArr[j] <<" "<<inputArr[temp];
          }
     }
     getchar();
}
int main()
{
    testSearchValue();
    getchar();
    getchar();
    return 0;
}
